package org.happyinsure.exe;

import javax.swing.DefaultCellEditor;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.table.TableColumn;

import org.happyinsure.structure.Row;
import org.happyinsure.structure.Row.Type;
import org.happyinsure.structure.TableModel;

public class Main {
	
	private static void createAndShowGUI() throws Exception {
		JFrame frame = new JFrame("Happy Insure");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLocationRelativeTo(null);
        
        JTable table = new JTable(new TableModel());
        table.setAutoCreateRowSorter(true);
        JComboBox<Type> typeBox = new JComboBox<>(Type.values());
        TableColumn typeColumn = table.getColumnModel().getColumn(Row.getTypeColumnIndex());
        typeColumn.setCellEditor(new DefaultCellEditor(typeBox));
        
        JScrollPane pane = new JScrollPane(table);
        frame.add(pane);
        frame.pack();
        frame.setVisible(true);
	}

	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			@Override
			public void run() {
				try {
					createAndShowGUI();
				} catch (Exception e) {
					System.err.println("Error creating GUI: ");
					e.printStackTrace();
				}
			}
		});
	}
}
